//
//  InputBar.m
//  QSBK
//
//  Created by Eric Wang on 4/23/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//
#import "Common.h"
#import "InputBar.h"

@implementation InputBar
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        [self addInputButton];
    }
    return self;
}


- (void)addInputButton
{
    CGFloat height = self.frame.size.height;
    
    UIButton *button1 = [[UIButton alloc]init];
    button1.tag = 1000;
    [button1 setImage:[UIImage imageNamed:@"icon_album.png"] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(inputButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    button1.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake((ScreenW-height)/2, 0, height, height)];
    button2.tag = 1001;
    [button2 addTarget:self action:@selector(inputButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [button2 setImage:[UIImage imageNamed:@"icon_camera.png"] forState:UIControlStateNormal];
    
    
    UIButton *button3 = [[UIButton alloc]init];
    button3.tag = 1002;
    [button3 addTarget:self action:@selector(inputButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [button3 setImage:[UIImage imageNamed:@"icon_video.png"] forState:UIControlStateNormal];
    button3.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    [self addSubview:button1];
    [self addSubview:button2];
    [self addSubview:button3];
    
    _constraint = [[NSMutableArray alloc]init];
    
    [_constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-30-[button1(height)]-(>=0)-|" options:0 metrics:@{@"height":@(height)} views:@{@"button1":button1}]];
    [_constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[button1]-0-|" options:0 metrics:nil views:@{@"button1":button1}]];
    [_constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(>=0)-[button3(height)]-30-|" options:0 metrics:@{@"height":@(height)} views:@{@"button3":button3}]];
    [_constraint addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[button3]-0-|" options:0 metrics:nil views:@{@"button3":button3}]];
    
    [self addConstraints:_constraint];
}

-(void)inputButtonClick:(UIButton *)button
{
    switch (button.tag) {
        case 1000:
            if(self.delegate!=nil&&[self.delegate respondsToSelector:@selector(picTouched)])
                                    {
                                        [self.delegate picTouched];
                                    }
            break;
            
        case 1001:
            if(self.delegate!=nil&&[self.delegate respondsToSelector:@selector(cameraTouched)])
            {
                [self.delegate cameraTouched];
            }
        case 1002:
            if(self.delegate!=nil&&[self.delegate respondsToSelector:@selector(videoTouched)])
            {
                [self.delegate videoTouched];
            }
        default:
            break;
    }
}
@end
